package com.yearEndWorkload.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yearEndWorkload.common.Result;
import com.yearEndWorkload.pojo.entity.ServicePerformance;
import com.yearEndWorkload.pojo.entity.WorkloadLoad;
import com.yearEndWorkload.pojo.form.add.AddServicePerformanceForm;
import com.yearEndWorkload.pojo.form.update.UpdateServicePerformanceForm;
import com.yearEndWorkload.service.ServicePerformanceService;
import com.yearEndWorkload.mapper.ServicePerformanceMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author admin
* @description 针对表【service_performance(管理服务绩效管理表)】的数据库操作Service实现
* @createDate 2024-03-06 22:45:38
*/
@Service
public class ServicePerformanceServiceImpl extends ServiceImpl<ServicePerformanceMapper, ServicePerformance>
    implements ServicePerformanceService{
    @Resource
    private ServicePerformanceMapper servicePerformanceMapper;

    @Override
    public Result<?> addServicePerformance(AddServicePerformanceForm addServicePerformanceForm) {
        ServicePerformance servicePerformance = new ServicePerformance();
        servicePerformance.setYear(addServicePerformanceForm.getYear());
        servicePerformance.setTeacherName(addServicePerformanceForm.getTeacherName());
        servicePerformance.setManagerAmounts(addServicePerformanceForm.getManagerAmounts());
        servicePerformance.setReporter(addServicePerformanceForm.getReporter());
        servicePerformanceMapper.insert(servicePerformance);
        return Result.success(null);
    }

    @Override
    public Result<?> deleteServicePerformance(Integer[] ids) {
        servicePerformanceMapper.deleteBatchIds(Arrays.asList(ids));
        return Result.success(null);
    }

    @Override
    public Result<List<ServicePerformance>> getServicePerformanceList(Long pageNumber, Long pageSize) {
        Page<ServicePerformance> page = new Page<>(pageNumber,pageSize);
        List<ServicePerformance> servicePerformanceList = servicePerformanceMapper.selectPage(page,null).getRecords();
        return Result.success(servicePerformanceList);
    }

    @Override
    public Result<?> updateServicePerformance(UpdateServicePerformanceForm updateServicePerformanceForm) {
        LambdaUpdateWrapper<ServicePerformance> updateWrapper = new LambdaUpdateWrapper<>();
        servicePerformanceMapper.update(null,updateWrapper.eq(ServicePerformance::getId,updateServicePerformanceForm.getId())
                .set(ServicePerformance::getYear,updateServicePerformanceForm.getYear())
                .set(ServicePerformance::getTeacherName,updateServicePerformanceForm.getTeacherName())
                .set(ServicePerformance::getManagerAmounts,updateServicePerformanceForm.getManagerAmounts())
                .set(ServicePerformance::getReporter,updateServicePerformanceForm.getReporter()));
        return Result.success(null);
    }
}




